#lang racket/base
(require racket/contract
		 racket/set
		 racket/function
		 "definition.rkt")
(provide (all-defined-out))

(define/contract (dispose dsp)
  (-> disposable? any)
  (set-disposable-disposed! dsp #t)
  (for-each dispose (set->list (disposable-subdsps dsp)))
  ((disposable-on-dispose dsp) dsp))

(define/contract disposable-add
  (->* (disposable?) () #:rest (listof disposable?) any)
  (lambda (dsp . rest-dsp)
	(for-each (curry set-add! (disposable-subdsps dsp)) rest-dsp)))

(module+ test
  (let ([dsp (disposable #f (mutable-seteq) void)]
		[dsp1 (disposable #f (mutable-seteq) void)]
		[dsp2 (disposable #f (mutable-seteq) void)]
		[dsp3 (disposable #f (mutable-seteq) void)])
	(disposable-add dsp dsp1 dsp2 dsp3)))
